package com.ycMc.common.bean;

import java.util.List;

public class PageBean {
	private List list; // 要返回的某一页得记录
	private int currentPage; // 当前页
	private int pageSize; // 每页记录数
	private boolean isLastPage;
	private int totalPages;
	private int totalCounts;

	public int getTotalCounts() {
		return totalCounts;
	}

	public void setTotalCounts(int totalCounts) {
		this.totalCounts = totalCounts;
	}

	public int getTotalPages() {
		return totalPages;
	}

	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}




	/**
	 * 计算当前页开始记录
	 * 
	 * @param pageSize
	 *            每页记录数
	 * @param currentPage
	 *            当前第几页
	 * @return 当前页开始记录号
	 */
	public static int countOffset(final int pageSize, final int currentPage) {
		if(currentPage == 0) {
			return 0;
		}
		final int offset = pageSize * (currentPage - 1);
		return offset;
	}

	public static int changePage(final int pageSize,final int currentPage,final int listSize){
		if(currentPage==0)
			return 1;
		if(pageSize*(currentPage-1)<listSize)
			return currentPage;
		return currentPage-(listSize%pageSize==0?listSize/pageSize:listSize/pageSize+1);
	}

	/**
	 * 计算当前页，若为0或者请求的URL中没有"?page=",则用1代替
	 * 
	 * @param page
	 *            传入的参数（可能为空，即0，则返回1）
	 * @return 当前页
	 */
	public static int countCurrentPage(int page) {
		final int curPage = (page == 0 ? 1 : page);
		return curPage;
	}

	public boolean isLastPage() {
		return isLastPage;
	}

	public void setLastPage(boolean isLastPage) {
		this.isLastPage = isLastPage;
	}

}
